package com.abso.mp3tunes.locker.ui.dialogs;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.dialogs.IInputValidator;

/**
 * An input validator for playlist names.
 */
public class PlaylistNameValidator implements IInputValidator {

	/** The current name of the playlist. */
	private String currentName;

	/**
	 * Constructs a new validator.
	 * 
	 * @param currentName
	 *            the current name of the playlist.
	 */
	public PlaylistNameValidator(String currentName) {
		this.currentName = currentName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
	 */
	public String isValid(String newText) {
		if (StringUtils.isEmpty(StringUtils.trimToEmpty(newText))) {
			return "Invalid name";
		} else if ((currentName != null) && currentName.equals(newText)) {
			return "";
		} else {
			return null;
		}
	}

}
